

s = 'ABC中文'

b = s.encode('gb2312')  # 转为GB2312格式的字节串
print('GB2312:', b)
b = s.encode('gbk')  # 转为GBK格式的字节串
print('GBK:', b)
b = s.encode('gb18030')  # 转为GB18030格式的字节串
print('GB18030:', b)

b2 = s.encode('utf-8')
print('UTF-8:', b2)